
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com/
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

 /* Account.java
 *
 * Created on Jan 27, 2011, 11:36:23 PM
 */

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;
import java.sql.*;

final class Account extends javax.swing.JInternalFrame {
    PreparedStatement statement;
    Systems systems=new Systems();
    Thread accountThread=new Thread();
    Thread accountTitleThread=new Thread();
    /** Creates new form TransactionType */
     Account() {
        initComponents();
        /* Execute submit thread */
        accountThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                resetBank();
                resetCurrency();
                reset();
            }
        });
        accountTitleThread=new Thread(new Runnable() {
            public void run() {
                while(accountThread.isAlive())setProcessingTitle(accountTitleThread);
                enableControls();
                System.out.println("accountThread stopped runing.");
            }
        });
        accountThread.start();
        accountTitleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jAccountNameTextField = new javax.swing.JTextField();
        jAccountRegisterButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jAccountNumberTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jBankComboBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jAccountDescriptionTextArea = new javax.swing.JTextArea();
        jAccountValueComboBox = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jAccountCategoryComboBox = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jCurrencyComboBox = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jTradingTypeComboBox = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jCashFlowsComboBox = new javax.swing.JComboBox();

        setClosable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(Account.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jAccountNameTextField.setText(resourceMap.getString("jAccountNameTextField.text")); // NOI18N
        jAccountNameTextField.setName("jAccountNameTextField"); // NOI18N
        jAccountNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jAccountNameTextFieldKeyTyped(evt);
            }
        });

        jAccountRegisterButton.setFont(resourceMap.getFont("jAccountRegisterButton.font")); // NOI18N
        jAccountRegisterButton.setIcon(resourceMap.getIcon("jAccountRegisterButton.icon")); // NOI18N
        jAccountRegisterButton.setText(resourceMap.getString("jAccountRegisterButton.text")); // NOI18N
        jAccountRegisterButton.setName("jAccountRegisterButton"); // NOI18N
        jAccountRegisterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAccountRegisterButtonActionPerformed(evt);
            }
        });

        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jAccountNumberTextField.setName("jAccountNumberTextField"); // NOI18N
        jAccountNumberTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jAccountNumberTextFieldKeyTyped(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jBankComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --" }));
        jBankComboBox.setName("jBankComboBox"); // NOI18N
        jBankComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBankComboBoxActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jAccountDescriptionTextArea.setColumns(20);
        jAccountDescriptionTextArea.setLineWrap(true);
        jAccountDescriptionTextArea.setRows(5);
        jAccountDescriptionTextArea.setName("jAccountDescriptionTextArea"); // NOI18N
        jScrollPane1.setViewportView(jAccountDescriptionTextArea);

        jAccountValueComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "ASSET", "N/A" }));
        jAccountValueComboBox.setEnabled(false);
        jAccountValueComboBox.setName("jAccountValueComboBox"); // NOI18N
        jAccountValueComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAccountValueComboBoxActionPerformed(evt);
            }
        });

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jAccountCategoryComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "REVENUE", "EXPENSE", "HYBRID", "PAYABLE", "RECEIVABLE", "INVENTORY", "INVENTORY PAYABLE", "INVENTORY RECEIVABLE", "ADJUSTMENT PAYABLE", "ADJUSTMENT RECEIVABLE" }));
        jAccountCategoryComboBox.setName("jAccountCategoryComboBox"); // NOI18N
        jAccountCategoryComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAccountCategoryComboBoxActionPerformed(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jCurrencyComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --" }));
        jCurrencyComboBox.setName("jCurrencyComboBox"); // NOI18N
        jCurrencyComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCurrencyComboBoxActionPerformed(evt);
            }
        });

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jTradingTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "SALE", "PURCHASE", "STOCK", "N/A" }));
        jTradingTypeComboBox.setName("jTradingTypeComboBox"); // NOI18N
        jTradingTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTradingTypeComboBoxActionPerformed(evt);
            }
        });

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jCashFlowsComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Operating Activity", "Financing Activity", "Investing Activity", "N/A" }));
        jCashFlowsComboBox.setName("jCashFlowsComboBox"); // NOI18N
        jCashFlowsComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCashFlowsComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 488, Short.MAX_VALUE)
                        .addComponent(jAccountRegisterButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel4))
                                .addGap(66, 66, 66)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jBankComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 239, Short.MAX_VALUE))
                                    .addComponent(jAccountNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(14, 14, 14)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jAccountNumberTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                                    .addComponent(jTradingTypeComboBox, 0, 315, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                                    .addComponent(jCashFlowsComboBox, 0, 315, Short.MAX_VALUE))))
                        .addGap(78, 78, 78)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jAccountCategoryComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 222, Short.MAX_VALUE)
                            .addComponent(jAccountValueComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 222, Short.MAX_VALUE)
                            .addComponent(jCurrencyComboBox, 0, 222, Short.MAX_VALUE))))
                .addGap(38, 38, 38))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jAccountNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jAccountCategoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jAccountValueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jBankComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jAccountNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jCurrencyComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel5)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jAccountRegisterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jTradingTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jCashFlowsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jAccountRegisterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAccountRegisterButtonActionPerformed
        // TODO add your handling code here:
        if(jAccountNameTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE ENTER ACCOUNT'S NAME ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jCurrencyComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT ACCOUNT'S CURRENCY ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jAccountNumberTextField.getText().trim().isEmpty()==false&&systems.isStringDigit(jAccountNumberTextField.getText().trim())==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"ACCOUNT NUMBER MUST BE IN DIGIT ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountDescriptionTextArea.getText().trim().isEmpty())
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE ENTER ACCOUNT'S DESCRIPTION ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT ACCOUNT'S CATEGORY ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT ACCOUNT'S VALUE ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("REVENUE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("ASSET")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! REVENUE ACCOUNT HAS ASSET VALUE","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("EXPENSE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("ASSET")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! EXPENSES ACCOUNT HAS ASSET VALUE","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("HYBRID")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("ASSET")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! \n HYBRID ACCOUNT HAS ASSET VALUE","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("PAYABLE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("ASSET")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! \n PAYABLE ACCOUNT HAS ASSET VALUE","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("RECEIVABLE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("ASSET")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! \n RECEIVABLE ACCOUNT HAS ASSET VALUE","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("INVENTORY")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("N/A")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("INVENTORY RECEIVABLE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("N/A")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("INVENTORY PAYABLE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("N/A")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("ADJUSTMENT PAYABLE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("N/A")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("ADJUSTMENT RECEIABLE")&&jAccountValueComboBox.getSelectedItem().toString().equalsIgnoreCase("N/A")==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT CATEGORY AND VALUE ARE INCOMPATIBLE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jTradingTypeComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," PLEASE SELECT ACCOUNT'S TRADING TYPE ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        if(jCashFlowsComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," PLEASE SELECT ACCOUNT'S CASH FLOWS ACTIVITY ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        else
        {
            /* Execute submit thread */
            accountThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    submitData();
                    reset();
                }
            });
            accountTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(accountThread.isAlive())setProcessingTitle(accountTitleThread);
                    enableControls();
                    System.out.println("accountThread stopped runing.");
                }
            });
            accountThread.start();
            accountTitleThread.start();
        }
    }//GEN-LAST:event_jAccountRegisterButtonActionPerformed
                                       
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. New Account - Processing Request");
            thread.sleep(500);
            this.setTitle("::. New Account - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. New Account - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. New Account - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        if(accountThread.isAlive())
        {
            try{
                accountThread.stop();
                accountTitleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. New Account");
            enableControls();
        }
        else
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jAccountNameTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jAccountNameTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jAccountNameTextField.getText();
        if(value.length()>29)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (30) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 29);
        jAccountNameTextField.setText(newValue);
        }
    }//GEN-LAST:event_jAccountNameTextFieldKeyTyped

    private void jAccountNumberTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jAccountNumberTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jAccountNumberTextField.getText();
        if(value.length()>39)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (40) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
            String newValue=String.copyValueOf(value.toCharArray(),0, 39);
            jAccountNumberTextField.setText(newValue);
        }
    }//GEN-LAST:event_jAccountNumberTextFieldKeyTyped

    private void jBankComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBankComboBoxActionPerformed
        // TODO add your handling code here:
        String bank=jBankComboBox.getSelectedItem().toString();
        if(bank.equals("-- Select --")) {
            resetBank();
        }
}//GEN-LAST:event_jBankComboBoxActionPerformed

    private void jAccountValueComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAccountValueComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jAccountValueComboBoxActionPerformed

    private void jAccountCategoryComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAccountCategoryComboBoxActionPerformed
        // TODO add your handling code here:
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("REVENUE"))
        {
            jAccountValueComboBox.setSelectedItem("ASSET");
            jTradingTypeComboBox.setSelectedItem("SALE");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("Operating Activity");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("EXPENSE"))
        {
            jAccountValueComboBox.setSelectedItem("ASSET");
            jTradingTypeComboBox.setSelectedItem("PURCHASE");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("-- Select --");
            jCashFlowsComboBox.setEnabled(true);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("HYBRID"))
        {
            jAccountValueComboBox.setSelectedItem("ASSET");
            jTradingTypeComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setEnabled(false);
            jCashFlowsComboBox.setSelectedItem("Financing Activity");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("PAYABLE"))
        {
            jAccountValueComboBox.setSelectedItem("ASSET");
            jTradingTypeComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setEnabled(false);
            jCashFlowsComboBox.setSelectedItem("Financing Activity");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("RECEIVABLE"))
        {
            jAccountValueComboBox.setSelectedItem("ASSET");
            jTradingTypeComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setEnabled(false);
            jCashFlowsComboBox.setSelectedItem("Financing Activity");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("INVENTORY"))
        {
            jAccountValueComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setSelectedItem("STOCK");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("N/A");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("INVENTORY RECEIVABLE"))
        {
            jAccountValueComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setSelectedItem("SALE");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("N/A");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("INVENTORY PAYABLE"))
        {
            jAccountValueComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setSelectedItem("PURCHASE");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("N/A");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("ADJUSTMENT PAYABLE"))
        {
            jAccountValueComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setSelectedItem("PURCHASE");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("N/A");
            jCashFlowsComboBox.setEnabled(false);
        }
        if(jAccountCategoryComboBox.getSelectedItem().toString().equalsIgnoreCase("ADJUSTMENT RECEIVABLE"))
        {
            jAccountValueComboBox.setSelectedItem("N/A");
            jTradingTypeComboBox.setSelectedItem("SALE");
            jTradingTypeComboBox.setEnabled(true);
            jCashFlowsComboBox.setSelectedItem("N/A");
            jCashFlowsComboBox.setEnabled(false);
        }
    }//GEN-LAST:event_jAccountCategoryComboBoxActionPerformed

private void jCurrencyComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCurrencyComboBoxActionPerformed
// TODO add your handling code here:
        String currency=jCurrencyComboBox.getSelectedItem().toString();
        if(currency.equals("-- Select --")) {
            resetCurrency();
        }
}//GEN-LAST:event_jCurrencyComboBoxActionPerformed

private void jTradingTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTradingTypeComboBoxActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTradingTypeComboBoxActionPerformed

private void jCashFlowsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCashFlowsComboBoxActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCashFlowsComboBoxActionPerformed
    public void resetCombo()
    {
        resetBank();
        resetCurrency();
        jAccountValueComboBox.setSelectedItem("-- Select --");
        jTradingTypeComboBox.setSelectedItem("-- Select --");
        jCashFlowsComboBox.setSelectedItem("-- Select --");
        jAccountCategoryComboBox.setSelectedItem("-- Select --");
    }
    void reset()
    {
        jAccountNameTextField.setText("");
        jAccountNumberTextField.setText("");
        jAccountDescriptionTextArea.setText("");
        resetBank();
        resetCurrency();
        jAccountValueComboBox.setSelectedItem("-- Select --");
        jAccountCategoryComboBox.setSelectedItem("-- Select --");
        jTradingTypeComboBox.setSelectedItem("-- Select --");
        jCashFlowsComboBox.setSelectedItem("-- Select --");
    }
    void disableControls()
    {
        jAccountNameTextField.setEditable(false);
        jAccountNameTextField.setEnabled(false);
        
        jAccountNumberTextField.setEditable(false);
        jAccountNumberTextField.setEnabled(false);
        
        jAccountDescriptionTextArea.setEditable(false);
        jAccountDescriptionTextArea.setEnabled(false);
        
        jBankComboBox.setEditable(false);
        jBankComboBox.setEnabled(false);
        
        jCurrencyComboBox.setEditable(false);
        jCurrencyComboBox.setEnabled(false);
                
        jAccountValueComboBox.setEditable(false);
        jAccountValueComboBox.setEnabled(false);
        
        jAccountCategoryComboBox.setEditable(false);
        jAccountCategoryComboBox.setEnabled(false);
                
        jTradingTypeComboBox.setEditable(false);
        jTradingTypeComboBox.setEnabled(false);
        
        jCashFlowsComboBox.setEditable(false);
        jCashFlowsComboBox.setEnabled(false);
        
        jAccountRegisterButton.setEnabled(false);
    }
     void enableControls()
    {
        jAccountNameTextField.setEditable(true);
        jAccountNameTextField.setEnabled(true);
        
        jAccountNumberTextField.setEditable(true);
        jAccountNumberTextField.setEnabled(true);
        
        jAccountDescriptionTextArea.setEditable(true);
        jAccountDescriptionTextArea.setEnabled(true);
        
        jBankComboBox.setEnabled(true);
        
        jCurrencyComboBox.setEnabled(true);
                
        jAccountValueComboBox.setEnabled(true);
        
        jAccountCategoryComboBox.setEnabled(true);
                
        jTradingTypeComboBox.setEnabled(true);
        
        jCashFlowsComboBox.setEnabled(true);
        
        jAccountRegisterButton.setEnabled(true);
        
        this.setTitle("::. New Account");
    }
     void resetCurrency()
    {
        String[] currency=systems.getTableDataArray(OpenMSApp.Database_A,"currency",2);
        currency[0]="-- Select --";

        jCurrencyComboBox.setModel(new DefaultComboBoxModel(currency));
    }
     void resetBank()
    {
        String[] bank=systems.getTableDataArray(OpenMSApp.Database_A,"bank",2);
        bank[0]="-- Select --";

        jBankComboBox.setModel(new DefaultComboBoxModel(bank));
    }
     String getBank()
    {
        String bank=String.valueOf(jBankComboBox.getSelectedItem());

        if(bank.equals("-- Select --"))
        {
            bank="";
        }
        return bank;
    }

    void submitData()
    {
        //Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+" prnInsAccount"+Connect.procInitStart+" ?,?,?,?,?,?,?,?,?"+Connect.procInitEnd);
            try{
                statement.setString(1,jAccountNameTextField.getText());
                statement.setString(2,getBank());
                statement.setString(3,jAccountNumberTextField.getText());
                statement.setString(4,jCurrencyComboBox.getSelectedItem().toString().trim());
                statement.setString(5,jAccountDescriptionTextArea.getText());
                statement.setString(6,jAccountValueComboBox.getSelectedItem().toString().trim());
                statement.setString(7,jAccountCategoryComboBox.getSelectedItem().toString().trim());
                statement.setString(8,jTradingTypeComboBox.getSelectedItem().toString().trim());
                statement.setString(9,jCashFlowsComboBox.getSelectedItem().toString().trim());
            }
            catch(Exception e)
            {
                System.out.println("Account.submitData() gave error ! "+e);
            }
        Connect.alert="Y";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jAccountCategoryComboBox;
    private javax.swing.JTextArea jAccountDescriptionTextArea;
    private javax.swing.JTextField jAccountNameTextField;
    private javax.swing.JTextField jAccountNumberTextField;
    private javax.swing.JButton jAccountRegisterButton;
    private javax.swing.JComboBox jAccountValueComboBox;
    private javax.swing.JComboBox jBankComboBox;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jCashFlowsComboBox;
    private javax.swing.JComboBox jCurrencyComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jTradingTypeComboBox;
    // End of variables declaration//GEN-END:variables

}
